package com.tjec.project.mdmSynchronous.controller;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.security.access.prepost.PreAuthorize;
import org.apache.xmlbeans.impl.xb.xsdschema.TotalDigitsDocument.TotalDigits;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.datetime.DateFormatter;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tjec.framework.aspectj.lang.annotation.Log;
import com.tjec.framework.aspectj.lang.enums.BusinessType;
import com.tjec.project.mdmSynchronous.domain.RejectComment;
import com.tjec.project.mdmSynchronous.domain.SysAdministrative;
import com.tjec.project.mdmSynchronous.service.IBpmRejectCommentService;
import com.tjec.project.mdmSynchronous.service.ISysAdministrativeService;
import com.tjec.project.system.domain.BmsMdWorkflowConfig;
import com.tjec.project.system.service.IBmsMdWorkflowConfigService;
import com.tjec.framework.web.controller.BaseController;
import com.tjec.framework.web.domain.AjaxResult;
import com.tjec.common.utils.StringUtils;
import com.tjec.common.utils.poi.ExcelUtil;
import com.tjec.framework.web.page.TableDataInfo;

/**
 * 驳回意见Controller
 * 
 * @author villwangpangyongfeng
 * @date 2021-01-08
 */
@RestController
@RequestMapping("/bpm/bpmRejectComment")
public class BpmRejectCommentController extends BaseController
{
    @Autowired
    private IBpmRejectCommentService bpmRejectCommentService;
    
    @Autowired
    private IBmsMdWorkflowConfigService bmsMdWorkflowConfigService;

    /**
     * 查询驳回意见列表
     */
    //@PreAuthorize("@ss.hasPermi('system:administrative:list')")
    @GetMapping("/list")
    public AjaxResult list(RejectComment rejectComment)
    {
    	Map<String, Object> resMap = new HashMap<String,Object>();
    	int pageNum = rejectComment.getPageNum();
    	int pageSize = rejectComment.getPageSize();
    	int total = pageSize*(pageNum-1);
    	rejectComment.setTotal(total);
    	if(!StringUtils.isNotBlank(rejectComment.getBizObjectSchemaCode())) {
    		BmsMdWorkflowConfig bmsMdWorkflowConfig = new BmsMdWorkflowConfig();
    		bmsMdWorkflowConfig.setStatus("1");
    		List<BmsMdWorkflowConfig> res = bmsMdWorkflowConfigService.selectBmsMdWorkflowConfigList(bmsMdWorkflowConfig);
    		if(res!=null && res.size()>0) {
    			List<String> codeList = new ArrayList<String>();
    			for (BmsMdWorkflowConfig bmsMdWorkflowConfig2 : res) {
    				codeList.add(bmsMdWorkflowConfig2.getUrl());
				}
    			if(codeList!=null && codeList.size()>0) {
    				rejectComment.setBizObjectSchemaCode(StringUtils.join(codeList,","));
    			}
    		}
    	}
    	
        List<Map<String, Object>> list = bpmRejectCommentService.getRejectCommentList(rejectComment);
        if(list!=null && list.size()>0) {
        	List<Map<String, Object>> resList = bpmRejectCommentService.getRejectCommentCounts(rejectComment);
        	for (Map<String, Object> map : resList) {
        		resMap.put("total", map.get("counts"));
			}
        	resMap.put("resList", list);
        	
        }
        return AjaxResult.success(resMap);
    }
    
    /**
     * 查询驳回意见列表
     */
    //@PreAuthorize("@ss.hasPermi('system:administrative:list')")
    @GetMapping("/workflowList")
    public AjaxResult workflowList()
    {
    	BmsMdWorkflowConfig bmsMdWorkflowConfig = new BmsMdWorkflowConfig();
		bmsMdWorkflowConfig.setStatus("1");
    	List<BmsMdWorkflowConfig> res = bmsMdWorkflowConfigService.selectBmsMdWorkflowConfigList(bmsMdWorkflowConfig);
    	return AjaxResult.success(res);
    }
    
    @GetMapping("/syncRejectList")
    public AjaxResult syncRejectList()
    {
    	int res = bpmRejectCommentService.syncRejectList();
    	return AjaxResult.success(res);
    }
    
}
